/**
 * Definition of DListTest.hpp. The most tests were implemented during the
 * implementation or by looking for the reason of bugs. So many tests seem
 * to be a little extreme but there is no reason to remove any test after
 * solving a bug.
 *
 * Note: You can check out all sources as eclipse cpp project
 *       over http://stuff-from-hell.googlecode.com/svn/trunk/cpp_ex
 *
 * @author  Benjamin Friedrich (3453464)
 * 			benjamin_friedrich@gmx.de
 * @version 1.0  13.01.2009
 */
#include "DListTest.hpp"
#include <cstring>

//-- constants used by the tests
static const char *TEST_STRING1 = "TestOne";
static const char *TEST_STRING2 = "TestTwo";
static const char *TEST_STRING3 = "TestThree";
static const char *TEST_STRING4 = "TestFour";
static const char *TEST_STRING5 = "TestFive";

/*
 *	Tests whether all attributes are correct set
 *	by the implemented standard constructor.
 */
void DListTest::testStandardConstructor()
{
	DList list;
	CPPUNIT_ASSERT(list.numberOfElements == 0);
	CPPUNIT_ASSERT(list.first            == 0);
	CPPUNIT_ASSERT(list.last             == 0);
}

/*
 * Tests the copy constructor of DList with 2 instances of DList.
 * At first, testCopyConstructor() creates the instance sourceList
 * with the standard constructor and fills it with test strings.
 * Then testCopyConstructor() creates the instance cloneList with
 * the copy constructor with sourceList as parameter. After this,
 * testCopyConstructor() checks whether both have the same value in
 * the attribute 'numberOfElements' and whether the pointers of the
 * attributes 'first' and 'last' of sourceList and cloneList are not
 * equal (so not copied) but have the same character string. At last,
 * there is a string comparison of the return value of the toString()
 * - method of both lists.
 */
void DListTest::testCopyConstructor()
{
	//-- creates and fills the DList instance sourceList
	DList sourceList;
	sourceList.pushBack(TEST_STRING1);
	sourceList.pushBack(TEST_STRING2);
	sourceList.pushBack(TEST_STRING3);
	sourceList.pushBack(TEST_STRING4);
	sourceList.pushBack(TEST_STRING5);

	//-- creates sourceList by calling the copy constructor with sourceList as parameter
	DList cloneList(sourceList);

	//-- runs the tests described above
	CPPUNIT_ASSERT(sourceList.numberOfElements == cloneList.numberOfElements);

	CPPUNIT_ASSERT(sourceList.first != cloneList.first);
	CPPUNIT_ASSERT(sourceList.last  != cloneList.last);

	CPPUNIT_ASSERT(! strcmp(sourceList.first->charString, cloneList.first->charString));
	CPPUNIT_ASSERT(! strcmp(sourceList.last ->charString, cloneList.last ->charString));

	CPPUNIT_ASSERT( sourceList.toString() == cloneList.toString());
}

/*
 * Tests the construction of DList with an array of character strings.
 * Therefore testStringArrayConstructor() uses an array consisting of
 * the TEST_STRING - constants for calling this constructor. The test
 * consists of a check for correct value of the DList attribute
 * numberOfElements and for the right positioning of each string within
 * the DList with the help of the DList operator [].
 */
void DListTest::testStringArrayConstructor()
{
	const char *strings[5] = {  TEST_STRING1,
								TEST_STRING2,
								TEST_STRING3,
								TEST_STRING4,
								TEST_STRING5  };

	DList list(strings, 5);

	CPPUNIT_ASSERT(list.numberOfElements == 5);
	CPPUNIT_ASSERT(! strcmp(list[0], TEST_STRING1) );
	CPPUNIT_ASSERT(! strcmp(list[1], TEST_STRING2) );
	CPPUNIT_ASSERT(! strcmp(list[2], TEST_STRING3) );
	CPPUNIT_ASSERT(! strcmp(list[3], TEST_STRING4) );
	CPPUNIT_ASSERT(! strcmp(list[4], TEST_STRING5) );
}

/*
 * Tests the DList operator "=". At first, testOperatorAssign()
 * creates the DList instance sourceList and fills it with test
 * strings. Then it assigns sourceList to the empty list targetList.
 * After the check of the state of both instances, testOperatorAssign()
 * creates and fills the DList newList. After that testOperatorAssign()
 * assigns newList to targetList, so targetList must have the same state
 * as newList (of course without copied pointers).
 */
void DListTest::testOperatorAssign()
{
	DList sourceList;
	sourceList.pushBack(TEST_STRING1);
	sourceList.pushBack(TEST_STRING2);
	sourceList.pushBack(TEST_STRING3);

	DList targetList = sourceList;

	CPPUNIT_ASSERT(sourceList.numberOfElements == targetList.numberOfElements);
	CPPUNIT_ASSERT(sourceList.first != targetList.first);
	CPPUNIT_ASSERT(sourceList.last  != targetList.last);
	CPPUNIT_ASSERT(! strcmp(sourceList.first->charString, targetList.first->charString));
	CPPUNIT_ASSERT(! strcmp(sourceList.last ->charString, targetList.last ->charString));
	CPPUNIT_ASSERT(sourceList.toString() == targetList.toString());

	DList newList;
	newList.pushFront(TEST_STRING1);
	newList.pushFront(TEST_STRING2);

	targetList = newList;
	CPPUNIT_ASSERT(targetList.numberOfElements == newList.numberOfElements);
	CPPUNIT_ASSERT(targetList.first            != newList.first);
	CPPUNIT_ASSERT(targetList.last             != newList.last);
	CPPUNIT_ASSERT(! strcmp(targetList.first->charString, newList.first->charString));
	CPPUNIT_ASSERT(! strcmp(targetList.last ->charString, newList.last->charString));
	CPPUNIT_ASSERT(targetList == newList);
}

/*
 * Tests the operator "==" by using two instances of DList.
 * Look at the comments below to see the tests of this operator.
 */
void DListTest::testOperatorEqual()
{
	DList listA;
	DList listB;

	//-- both lists are empty so both must be equal
	CPPUNIT_ASSERT(listA == listB);


	listA.pushBack(TEST_STRING1);
	//-- listA has one more element as listB
	CPPUNIT_ASSERT( !(listA == listB) );

	listB.pushBack(TEST_STRING1);
	//-- listB has one element too and the inserted string is the same as by listB
	//   so both must be equal
	CPPUNIT_ASSERT(listA == listB);

	listA.pushFront(TEST_STRING2);
	//-- listA has one more element as listB, so both are not equal
	CPPUNIT_ASSERT( !(listA == listB) );

	listB.pushBack(TEST_STRING2);
	//-- now both lists have the same number of elements and both lists have
	//   the same string but TEST_STRING2 in listA is on an other position
	//   as in listB, so both are not equal
	CPPUNIT_ASSERT( !(listA == listB) );

	//-- listA must be equal with itself
	CPPUNIT_ASSERT(listA == listA);

	listA = listB;
	//-- after assigning listB to listA, both must be equal
	CPPUNIT_ASSERT(listA == listB);

	listA.clear();
	listB.clear();
	//-- after clearing of both lists, both are empty and so, both must be equal
	CPPUNIT_ASSERT(listA == listB);
}


void DListTest::testOperatorNotEqual()
{
	DList list1;
	list1.pushBack(TEST_STRING1);
	list1.pushBack(TEST_STRING2);

	DList list2(list1);

	CPPUNIT_ASSERT(! (list1 != list2));

	list1.pushBack(TEST_STRING3);

	CPPUNIT_ASSERT(list1 != list2);
}

void DListTest::testOperatorPlusEqual()
{
	DList listHead;
	listHead.pushBack(TEST_STRING1);
	listHead.pushBack(TEST_STRING2);
	CPPUNIT_ASSERT(listHead.numberOfElements == 2);

	DList listTail;
	listTail.pushBack(TEST_STRING3);
	listTail.pushBack(TEST_STRING4);
	listTail.pushBack(TEST_STRING5);
	CPPUNIT_ASSERT(listTail.numberOfElements == 3);

	DList expectedList;
	expectedList.pushBack(TEST_STRING1);
	expectedList.pushBack(TEST_STRING2);
	expectedList.pushBack(TEST_STRING3);
	expectedList.pushBack(TEST_STRING4);
	expectedList.pushBack(TEST_STRING5);
	CPPUNIT_ASSERT(expectedList.numberOfElements == 5);

	listHead += listTail;
	CPPUNIT_ASSERT(listHead == expectedList);
}

void DListTest::testOperatorSubscript()
{
	DList list;
	CPPUNIT_ASSERT(list[0] == NULL);
	CPPUNIT_ASSERT(list[1] == NULL);

	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	list.pushBack(TEST_STRING4);
	list.pushBack(TEST_STRING5);

	CPPUNIT_ASSERT(! strcmp(list[0], TEST_STRING1) );
	CPPUNIT_ASSERT(! strcmp(list[1], TEST_STRING2) );
	CPPUNIT_ASSERT(! strcmp(list[2], TEST_STRING3) );
	CPPUNIT_ASSERT(! strcmp(list[3], TEST_STRING4) );
	CPPUNIT_ASSERT(! strcmp(list[4], TEST_STRING5) );
	CPPUNIT_ASSERT(list[5] == NULL);
}


void DListTest::testOperatorPlus()
{
	DList list1;
	list1.pushBack(TEST_STRING1);
	list1.pushBack(TEST_STRING2);
	CPPUNIT_ASSERT(list1.numberOfElements == 2);

	DList list2;
	list2.pushBack(TEST_STRING3);
	list2.pushBack(TEST_STRING4);
	list2.pushBack(TEST_STRING5);
	CPPUNIT_ASSERT(list2.numberOfElements == 3);

	const DList &newList = list1 + list2;
	CPPUNIT_ASSERT(newList.numberOfElements == 5);
	CPPUNIT_ASSERT(! strcmp(newList.first->charString, list1.first->charString) );
	CPPUNIT_ASSERT(! strcmp(newList.last ->charString, list2.last ->charString) );
}

void DListTest::testPushFront()
{
	DList list;

	//-- DList: TEST_STRING1
	list.pushFront(TEST_STRING1);
	CPPUNIT_ASSERT(list.numberOfElements  == 1);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING1);
	CPPUNIT_ASSERT(list.last ->charString == TEST_STRING1);

	//-- DList: TEST_STRING2 - TEST_STRING1
	list.pushFront(TEST_STRING2);
	CPPUNIT_ASSERT(list.numberOfElements  == 2);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING2);
	CPPUNIT_ASSERT(list.last ->charString == TEST_STRING1);
	CPPUNIT_ASSERT(list.first->next       == list.last);
	CPPUNIT_ASSERT(list.first->previous   == NULL);
	CPPUNIT_ASSERT(list.last ->next       == NULL);
	CPPUNIT_ASSERT(list.last ->previous   == list.first);

	//-- DList: TEST_STRING3 - TEST_STRING2 - TEST_STRING1
	list.pushFront(TEST_STRING3);
	CPPUNIT_ASSERT(list.numberOfElements            == 3);
	CPPUNIT_ASSERT(list.first->charString           == TEST_STRING3);
	CPPUNIT_ASSERT(list.last ->charString           == TEST_STRING1);
	CPPUNIT_ASSERT(list.first->next->charString     == TEST_STRING2);
	CPPUNIT_ASSERT(list.first->previous             == NULL);
	CPPUNIT_ASSERT(list.last ->next                 == NULL);
	CPPUNIT_ASSERT(list.last ->previous->charString == TEST_STRING2);

    DListElement *insertedElement = list.first->next;
    CPPUNIT_ASSERT(insertedElement->previous->charString == TEST_STRING3);
    CPPUNIT_ASSERT(insertedElement->next    ->charString == TEST_STRING1);
}


void DListTest::testPushBack()
{
	DList list;

	list.pushBack(TEST_STRING1);
	CPPUNIT_ASSERT(list.numberOfElements == 1);
	CPPUNIT_ASSERT(list.first       != 0 && list.first->charString == TEST_STRING1);
	CPPUNIT_ASSERT(list.last        != 0 && list.last->charString  == TEST_STRING1);
    CPPUNIT_ASSERT(list.first->next == 0 && list.first->previous   == 0);

    list.pushBack(TEST_STRING2);
    CPPUNIT_ASSERT(list.numberOfElements == 2);
    CPPUNIT_ASSERT(list.first != 0 &&  list.first->charString == TEST_STRING1);
    CPPUNIT_ASSERT(list.last  != 0 &&  list.last->charString  == TEST_STRING2);
    CPPUNIT_ASSERT(list.first->next     == list.last);
    CPPUNIT_ASSERT(list.first->previous == 0);
    CPPUNIT_ASSERT(list.last->previous  == list.first);
    CPPUNIT_ASSERT(list.last->next      == 0);
}


void DListTest::testInsert()
{
	DList list;

	//-- Tests the insertion on a not yet valid position
	//-- DList: "-"
	CPPUNIT_ASSERT(!list.insert(666, TEST_STRING2));

	//-- Tests the insertion of a an element on the first position in an empty list
	//-- DLIST: "TEST_STRING1"
	CPPUNIT_ASSERT( list.insert(0,   TEST_STRING1));
	CPPUNIT_ASSERT(list.numberOfElements  == 1);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING1);
	CPPUNIT_ASSERT(list.first             == list.last);
	CPPUNIT_ASSERT(list.first->previous   == NULL);
	CPPUNIT_ASSERT(list.first->next       == NULL);


	//-- Tests the insertion of an element on the last position
	//-- DList: "TEST_STRING1 - TEST_STRING2"
	CPPUNIT_ASSERT(list.insert(1, TEST_STRING2));
	CPPUNIT_ASSERT(list.numberOfElements            == 2);
	CPPUNIT_ASSERT(list.first->charString           == TEST_STRING1);
	CPPUNIT_ASSERT(list.last ->charString           == TEST_STRING2);
	CPPUNIT_ASSERT(list.last ->previous->charString == TEST_STRING1);
	CPPUNIT_ASSERT(list.last ->next                 == NULL);

	//-- Tests the insertion of an element on the first position in a not empty list
	//-- DList: "TEST_STRING3 - TEST_STRING1 - TEST_STRING2"
	CPPUNIT_ASSERT(list.insert(0, TEST_STRING3));
	CPPUNIT_ASSERT(list.numberOfElements                  == 3);
	CPPUNIT_ASSERT(list.first->charString                 == TEST_STRING3);
	CPPUNIT_ASSERT(list.last ->charString                 == TEST_STRING2);
	CPPUNIT_ASSERT(list.first->next->charString           == TEST_STRING1);
	CPPUNIT_ASSERT(list.first->next->previous->charString == TEST_STRING3);
	CPPUNIT_ASSERT(list.first->next->next    ->charString == TEST_STRING2);

	//-- Tests the insertion  of an element on a position within two other elements
	//-- DList: "TEST_STRING3 - TEST_STRING4 - TEST_STRING1 - TEST_STRING2"
	CPPUNIT_ASSERT(list.insert(1, TEST_STRING4));
	CPPUNIT_ASSERT(list.first->charString                 == TEST_STRING3);
	CPPUNIT_ASSERT(list.last ->charString                 == TEST_STRING2);
	CPPUNIT_ASSERT(list.first->next->charString           == TEST_STRING4);
	CPPUNIT_ASSERT(list.first->next->previous->charString == TEST_STRING3);
	CPPUNIT_ASSERT(list.first->next->next    ->charString == TEST_STRING1);

}


void DListTest::testRemove()
{
	DList      list;
	const char *removedElement = 0;

	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	list.pushBack(TEST_STRING4);
	list.pushBack(TEST_STRING5);
	CPPUNIT_ASSERT(list.numberOfElements == 5);

	//-- Test the deletion of an element on not valid positions
	CPPUNIT_ASSERT(! list.remove(6));
	CPPUNIT_ASSERT(! list.remove(-1));

	//-- Tests the deletion of the first element in the list
	//-- DList: "TEST_STRING1 - TEST_STRING2 -TEST_STRING3 -TEST_STRING4 - TEST_STRING5"
	removedElement = list.remove(0);
	CPPUNIT_ASSERT(removedElement         != 0);
	CPPUNIT_ASSERT(list.numberOfElements  == 4);
	CPPUNIT_ASSERT(removedElement         == TEST_STRING1);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING2);
	CPPUNIT_ASSERT(list.last ->charString == TEST_STRING5);
	CPPUNIT_ASSERT(list.first->previous   == NULL);

	//-- Tests the deletion of the last element in the list
	//-- DList: "TEST_STRING2 -TEST_STRING3 -TEST_STRING4 - TEST_STRING5"
	removedElement = list.remove(3);
	CPPUNIT_ASSERT(removedElement         != 0);
	CPPUNIT_ASSERT(list.numberOfElements  == 3);
	CPPUNIT_ASSERT(removedElement         == TEST_STRING5);
	CPPUNIT_ASSERT(list.last->next        == NULL);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING2);
	CPPUNIT_ASSERT(list.last ->charString == TEST_STRING4);

	//-- Tests the deletion of an element within the list
	//-- DList: "TEST_STRING2 -TEST_STRING3 -TEST_STRING4"
	removedElement = list.remove(1);
	CPPUNIT_ASSERT(removedElement         != 0);
	CPPUNIT_ASSERT(list.numberOfElements  == 2);
	CPPUNIT_ASSERT(removedElement         == TEST_STRING3);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING2);
	CPPUNIT_ASSERT(list.last ->charString == TEST_STRING4);
	CPPUNIT_ASSERT(list.first->next       == list.last);
	CPPUNIT_ASSERT(list.last->previous    == list.first);

	CPPUNIT_ASSERT(list.remove(0));
	CPPUNIT_ASSERT(list.numberOfElements == 1);
	CPPUNIT_ASSERT(list.first            == list.last);
	CPPUNIT_ASSERT(list.first->previous  == NULL);
	CPPUNIT_ASSERT(list.first->next      == NULL);

	CPPUNIT_ASSERT(list.remove(0));
	CPPUNIT_ASSERT(list.numberOfElements == 0);
	CPPUNIT_ASSERT(list.first            == NULL);
	CPPUNIT_ASSERT(list.last             == NULL);

	CPPUNIT_ASSERT(! list.remove(0));
}


void DListTest::testPopBack()
{
	DList      list;
	const char *removedElement = 0;

	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	CPPUNIT_ASSERT(list.numberOfElements == 3);

	//-- DList: TEST_STRING1 - TEST_STRING2
	removedElement = list.popBack();
	CPPUNIT_ASSERT(removedElement);
	CPPUNIT_ASSERT(removedElement             == TEST_STRING3);
	CPPUNIT_ASSERT(list.numberOfElements  == 2);
	CPPUNIT_ASSERT(list.last->charString  == TEST_STRING2);
	CPPUNIT_ASSERT(list.last->next        == NULL);
	CPPUNIT_ASSERT(list.last->previous    == list.first);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING1);
	CPPUNIT_ASSERT(list.first->next       == list.last);
	CPPUNIT_ASSERT(list.first->previous   == NULL);

	//-- DList: TEST_STRING1
    removedElement = list.popBack();
    CPPUNIT_ASSERT(removedElement);
    CPPUNIT_ASSERT(removedElement             == TEST_STRING2);
    CPPUNIT_ASSERT(list.numberOfElements  == 1);
    CPPUNIT_ASSERT(list.first->charString == TEST_STRING1);
    CPPUNIT_ASSERT(list.first             == list.last);
    CPPUNIT_ASSERT(list.first->previous   == NULL);
    CPPUNIT_ASSERT(list.first->next       == NULL);

    //-- DList: -
    removedElement = list.popBack();
    CPPUNIT_ASSERT(removedElement);
    CPPUNIT_ASSERT(removedElement            == TEST_STRING1);
    CPPUNIT_ASSERT(list.numberOfElements == 0);
    CPPUNIT_ASSERT(list.first 			 == NULL);
    CPPUNIT_ASSERT(list.last 			 == NULL);
    CPPUNIT_ASSERT(! list.popBack());
}


void DListTest::testPopFront()
{
	DList      list;
	const char *removedElement = 0;

	//-- DList: TEST_STRING1 - TEST_STRING2 - TEST_STRING3
	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	CPPUNIT_ASSERT(list.numberOfElements == 3);

	//-- DList: TEST_STRING2 - TEST_STRING3
	removedElement = list.popFront();
	CPPUNIT_ASSERT(removedElement);
	CPPUNIT_ASSERT(removedElement         == TEST_STRING1);
	CPPUNIT_ASSERT(list.numberOfElements  == 2);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING2);
	CPPUNIT_ASSERT(list.first->previous   == NULL);
	CPPUNIT_ASSERT(list.first->next       == list.last);
	CPPUNIT_ASSERT(list.last->charString  == TEST_STRING3);
	CPPUNIT_ASSERT(list.last->previous    == list.first);
	CPPUNIT_ASSERT(list.last->next        == NULL);

	//-- DList: TEST_STRING3
	removedElement = list.popFront();
	CPPUNIT_ASSERT(removedElement);
	CPPUNIT_ASSERT(removedElement         == TEST_STRING2);
	CPPUNIT_ASSERT(list.numberOfElements  == 1);
	CPPUNIT_ASSERT(list.first->charString == TEST_STRING3);
	CPPUNIT_ASSERT(list.first             == list.last);
	CPPUNIT_ASSERT(list.first->next       == NULL);
	CPPUNIT_ASSERT(list.first->previous   == NULL);

	//-- DList: -
	removedElement = list.popFront();
	CPPUNIT_ASSERT(removedElement);
	CPPUNIT_ASSERT(removedElement        == TEST_STRING3);
	CPPUNIT_ASSERT(list.numberOfElements == 0);
	CPPUNIT_ASSERT(list.first            == NULL);
	CPPUNIT_ASSERT(list.last             == NULL);
	CPPUNIT_ASSERT(! list.popFront());
}

void DListTest::testSize()
{
	DList list;

	CPPUNIT_ASSERT(list.size() == 0);
	CPPUNIT_ASSERT(list.size() == list.numberOfElements);

	list.pushBack(TEST_STRING1);
	CPPUNIT_ASSERT(list.size() == 1);
	CPPUNIT_ASSERT(list.size() == list.numberOfElements);

	list.pushBack(TEST_STRING2);
	CPPUNIT_ASSERT(list.size() == 2);
	CPPUNIT_ASSERT(list.size() == list.numberOfElements);
}

void DListTest::testToString()
{
	using namespace std;
	DList list;

	CPPUNIT_ASSERT(list.toString().empty());

	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	list.pushBack(TEST_STRING4);
	list.pushBack(TEST_STRING5);


	string expectedString  = TEST_STRING1;
	expectedString        += DList::TO_STRING_SEPARATOR;
	expectedString        += TEST_STRING2;
	expectedString        += DList::TO_STRING_SEPARATOR;
	expectedString        += TEST_STRING3;
	expectedString        += DList::TO_STRING_SEPARATOR;
	expectedString        += TEST_STRING4;
	expectedString        += DList::TO_STRING_SEPARATOR;
	expectedString        += TEST_STRING5;

	CPPUNIT_ASSERT(list.toString() == expectedString);
}

void DListTest::testClear()
{
	DList list;

	list.clear();
	CPPUNIT_ASSERT(list.numberOfElements == 0);
	CPPUNIT_ASSERT(list.first            == NULL);
	CPPUNIT_ASSERT(list.last             == NULL);

	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	list.pushBack(TEST_STRING4);
	list.pushBack(TEST_STRING5);

	CPPUNIT_ASSERT(list.numberOfElements == 5);

	list.clear();
	CPPUNIT_ASSERT(list.numberOfElements == 0);
	CPPUNIT_ASSERT(list.first            == NULL);
	CPPUNIT_ASSERT(list.last             == NULL);
}


void DListTest::testIterator()
{
	typedef DList::DListIterator Iterator;

	DList list;
	list.pushBack(TEST_STRING1);
	list.pushBack(TEST_STRING2);
	list.pushBack(TEST_STRING3);
	list.pushBack(TEST_STRING4);
	list.pushBack(TEST_STRING5);

	Iterator tmpIterator =  list.begin();
	CPPUNIT_ASSERT(! strcmp(*tmpIterator, TEST_STRING1) );

	CPPUNIT_ASSERT( list.begin() != list.end());
	CPPUNIT_ASSERT( list.begin() == list.begin());


	Iterator iterator1(list.first->next);
	Iterator iterator2(list.first->next);
	CPPUNIT_ASSERT(iterator1 == iterator2);

	Iterator iteratorWithLastListElement(list.last);
	CPPUNIT_ASSERT( iteratorWithLastListElement != list.end());

	unsigned int i = 0;
	for(Iterator iter = list.begin(); iter != list.end(); iter++)
	{
		CPPUNIT_ASSERT(*iter == list[i]);
		i++;
	}

	CPPUNIT_ASSERT(i == (list.numberOfElements));
}


bool DListTest::run()
{
	CppUnit::TextUi::TestRunner runner;
	runner.addTest(DListTest::suite());

	return runner.run();
}
